package service;

import mapper.TenantMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import po.Result;
import po.Tenant;

import java.util.List;

@Service
public class TenantServiceImpl implements TenantService {

    @Autowired
    private TenantMapper tenantMapper;

    @Override
    public List<Tenant> findAllTenants(Tenant tenant) throws Exception {
        return tenantMapper.findAllTenants(tenant);
    }

    @Override
    public Result addTenant(Tenant tenant) {
        Result result = new Result();
        try {
            tenantMapper.addTenant(tenant);
        } catch (Exception e) {
            //e.printStackTrace();
            result.setResult("fail");
            result.setMessage("添加失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("添加成功！");
        return result;
    }

    @Override
    public Result deleteTenantById(int id) {
        Result result = new Result();
        try {
            tenantMapper.deleteTenantById(id);
        } catch (Exception e) {
            //e.printStackTrace();
            result.setResult("fail");
            result.setMessage("删除失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("删除成功！");
        return result;
    }

    @Override
    public Result updateTenantById(int id, Tenant tenant) {
        Result result = new Result();
        tenant.setId(id);
        try {
            tenantMapper.updateTenantById(tenant);
        } catch (Exception e) {
            //e.printStackTrace();
            result.setResult("fail");
            result.setMessage("更新失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("更新成功！");
        return result;
    }
}
